package com.chukun.netty.protobuf;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LoggingHandler;

/**
 * @author chukun
 * 定义protobuf服务器的启动程序
 */
public class NettyprotoBufClient {

    private static final int PORT=8899;
    private void start() throws InterruptedException {
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        try{
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(workerGroup)
                           .channel(NioSocketChannel.class)
                           .handler(new LoggingHandler())
                           .handler(new NettyProtobufClientChannelInitializer());
            ChannelFuture future = bootstrap.connect("127.0.0.1",PORT).sync();
            future.channel().closeFuture().sync();
        }finally {
            workerGroup.shutdownGracefully();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        new NettyprotoBufClient().start();
    }
}
